package org.xserver.bootstrap.listener;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.xserver.bootstrap.listener.exception.BootstrapListenerError;
import org.xserver.component.config.XServerHttpConfig;
import org.xserver.component.core.interfaces.InterfaceContext;
import org.xserver.component.core.interfaces.InterfaceMeta;
import org.xserver.component.handler.XServerHttpInterceptor;
import org.xserver.component.listener.XServerListener;

@Component
public class XServerInterfaceContextListener extends AbstractBootstrapListener {

	@Resource
	private InterfaceContext interfaceContext;
	@Resource
	private XServerListener xServerListener;
	@Resource
	private XServerHttpConfig xServerHttpConfig;
	@Resource
	private XServerHttpInterceptor xServerHttpInterceptor;

	@Override
	protected void doProcess(String... args) throws BootstrapListenerError {
		Map<String, InterfaceMeta> interfaces = interfaceContext
				.getInterfaceContext();
		boolean isInterceptor = xServerHttpConfig.isInterceptor();

		for (String interfaceKey : interfaces.keySet()) {
			// initialize XServerListener
			xServerListener.putInterface(interfaceKey);

			if (isInterceptor) {// initialize XServerHttpInterceptor
				xServerHttpInterceptor.putInterface(interfaceKey);
			}
		}

	}

}
